from typing import List

# 时间上没有变快，内存消耗反而大了……
class Solution:
    def maxProduct(self, words: List[str]) -> int:
        wlen = len(words)
        m = [(words[i], words[j]) for i in range(wlen - 1) for j in range(i + 1, wlen)]
        m.sort(key=lambda it: len(it[0]) * len(it[1]), reverse=True)
        for (w1, w2) in m:
            if not self.__intersected(w1, w2):
                return len(w1) * len(w2)
        return 0

    def __intersected(self, str1, str2):
        for c in str1:
            if c in str2:
                return True
        return False


solu = Solution()
result = solu.maxProduct(["abcw", "baz", "foo", "bar", "xtfn", "abcdef"])
print(result)
